import 'package:flutter/material.dart';
import 'package:wallpaper_app/components/list_title/my_list_title_model.dart';
import 'package:wallpaper_app/tools/route_animation.dart';

class MyListTitle extends StatelessWidget {
  final List<MyListTitleModel> list;
  final double height;
  const MyListTitle({super.key, required this.list, this.height = 50});

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context).colorScheme;
    return Material(
      color: theme.primaryContainer,
      borderRadius: BorderRadius.circular(10),
      child: Column(
        children: [
          for (int i = 0; i < list.length; i++) ...[
            InkWell(
              borderRadius: i == 0
                  ? const BorderRadius.vertical(top: Radius.circular(10))
                  : i == list.length - 1
                      ? const BorderRadius.vertical(bottom: Radius.circular(10))
                      : BorderRadius.zero,
              onTap: () {
                // 自定义跳转动画
                if (list[i].route != null) {
                  RouteAnimation().animateRoute(context, list[i].route!);
                }
              },
              child: ListTile(
                minTileHeight: height,
                title: Text(list[i].title),
                leading: list[i].leading,
                trailing: const Icon(Icons.chevron_right_rounded),
                contentPadding: const EdgeInsets.symmetric(horizontal: 16),
              ),
            ),
            if (i != list.length - 1)
              Padding(
                padding: const EdgeInsets.only(left: 16), // 对齐leading图标
                child: Divider(
                  height: 1,
                  thickness: 0.5,
                  endIndent: 16,
                  color: Colors.grey[300],
                ),
              )
          ]
        ],
      ),
    );
  }
}
